package com.lyy.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyy.common.utils.UUIDUtils;
import com.lyy.project.dao.ProProjectUserDao;
import com.lyy.project.pojo.ProProjectUser;
import com.lyy.project.service.ProProjectUserService;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 项目用户(ProProjectUser)表服务实现类
 *
 * @author Yw
 * @since 2021-02-01 17:22:35
 */
@Service
public class ProProjectUserServiceImpl extends ServiceImpl<ProProjectUserDao, ProProjectUser> implements ProProjectUserService {


    /**
     * 添加项目用户
     *
     * @param proProjectUser
     */
    @Override
    public void createProProjectUser(ProProjectUser proProjectUser) {
        proProjectUser.setCreateDate(new Date());
        baseMapper.insert(proProjectUser);
    }

    /**
     * 根据主键修改项目用户
     *
     * @param proProjectUser
     */
    @Override
    public void updateProProjectUser(ProProjectUser proProjectUser) {
        baseMapper.update(proProjectUser, new UpdateWrapper<ProProjectUser>()
                .eq("id", proProjectUser.getId())
        );
    }

    /**
     * 根据主键删除项目用户
     *
     * @param id 项目用户id
     * @return
     */
    @Override
    public void deleteProProjectUser(ProProjectUser proProjectUser) {
        baseMapper.delete(new UpdateWrapper<ProProjectUser>()
                .eq("id", proProjectUser.getId())
        );
    }

    /**
     * 根据主键查询项目用户详情
     *
     * @param id 项目用户id
     * @return
     */
    @Override
    public ProProjectUser getProProjectUser(ProProjectUser proProjectUser) {
        return baseMapper.selectOne(new QueryWrapper<ProProjectUser>()
                .eq("id", proProjectUser.getId())
        );
    }

    /**
     * 批量添加项目用户
     *
     * @param proProjectUsers
     */
    @Override
    public int batchInsert(List<ProProjectUser> proProjectUsers) {
        return baseMapper.batchInsert(proProjectUsers);
    }


    /**
     * 批量修改项目用户
     *
     * @param proProjectUsers
     */
    @Override
    public int batchUpdate(List<ProProjectUser> proProjectUsers) {
        return baseMapper.batchUpdate(proProjectUsers);
    }

    /**
     * 查询项目用户列表
     *
     * @param proProjectUser
     */
    @Override
    public List<ProProjectUser> selectProProjectUserList(ProProjectUser proProjectUser) {
        return baseMapper.selectProProjectUserList(proProjectUser);
    }

    /**
     * 查询项目用户数量
     *
     * @param proProjectUser
     */
    @Override
    public int selectProProjectUserCount(ProProjectUser proProjectUser) {
        return baseMapper.selectProProjectUserCount(proProjectUser);
    }


    /**
     * 导入项目用户excel
     *
     * @param proProjectUsers
     */
    @Override
    public List<Map<String, String>> importProProjectUserExcel(List<ProProjectUser> proProjectUsers) {
        List<Map<String, String>> mapList = new ArrayList<>();
        proProjectUsers.forEach(proProjectUser -> {
            proProjectUser.setId(UUIDUtils.getUUIDTWO());
            Map<String, String> map = new HashMap<>();
            map.put("status", "0");
            map.put("reason", "导入成功");
            mapList.add(map);
        });
        batchInsert(proProjectUsers);
        return mapList;
    }
}